@extends('layouts.main')

@section('title', '客户规模')

@section('content')
<div class="btn-group" role="group">
    <a href="{{ action('Report\IndexController@index') }}" class="btn btn-primary">返回报表列表</a>
</div>
<div class="clearfix"></div>
<hr>
<h3>@yield('title')</h3>
<button id="cache" class="btn btn-primary">缓存数据</button>
<button id="export" class="btn btn-primary">导出表格</button>
<div class="clearfix"></div>
<hr>

<form class="form-inline pull-right" method="get" action="{{ action('Report\PayerScaleController@index') }}">
    
    <div class="form-group ">
        <label for="year">年份</label>
        <div class='input-group' >
            <input type='text' id='year' name="year" class="form-control" value="{{ $request_params['year'] }}" />
        </div>
    </div>

    <div class="form-group ">
        <label for="payer_code">客户代码</label>
        <div class='input-group'>
            <input type='text' id='payer_code' name="payer_code" class="form-control" value="{{ $request_params['payer_code'] }}" />
        </div>
    </div>

    <button type="submit" name="search" value="search" class="btn btn-primary">查询</button>

</form>

<div class="clearfix"></div>
<hr>

@include('report.payer_scale.table')

<script>
	$(document).ready(function(){
		//批量更新
		$('#cache').click(function(){
            //选择范围
            var year = $('#year').val();
            var payer_code = $('#payer_code').val();
			if(!$.isNumeric(year)){
				alert("请选择需要缓存数据的年份！");
				return;
			}

            $.post("/report/payer_scale/cache", {
                '_token': '{{ csrf_token() }}',
                'year': year,
                'payer_code': payer_code,
            }, function(data){
				if(data.status == 0){
					alert("数据缓存成功！");
				}else{
                    alert(data.info);
                }
            });
        });


        // //导出表格
		// $('#export').click(function(){
        //     //选择范围
        //     var year = $('#year').val();
        //     var month = $('#month').val();
		// 	if(!$.isNumeric(year) || !$.isNumeric(month)){
		// 		alert("请选择需要导出数据的年份和月份！");
		// 		return;
		// 	}
        //     // event.preventDefault();

        //     $.post("/report/region_contract_progress/export", {
        //         '_token': '{{ csrf_token() }}',
        //         'year': year,
        //         'month': month,
        //     }, function(data){
		// 		if(data.status == 0){
		// 			alert("导出数据成功，请至目录[/storage/app/export]下查询！");
		// 		}
        //     });
        // });
	});
</script>
@endsection